package com.itheima.ydd.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.ydd.dto.AdvposDto;
import com.itheima.ydd.dto.AdvposPage;
import com.itheima.ydd.entity.Advpos;
import com.itheima.ydd.entity.Result;
import com.itheima.ydd.service.AdvposService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author maorf
 * @version 1.0
 */
@RestController()
@RequestMapping("ydd_advpos")
public class AdvposController {
    @Autowired
    AdvposService service;

    /**
     * 分页返回
     * @param advposdesc
     * @param advposname
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<Result> list(@RequestParam String advposdesc, String advposname, Integer page, Integer limit){
        AdvposPage advposPage = service.getPage(advposdesc, advposname, page, limit);
        return  ResponseEntity.ok(new Result(0,"成功",advposPage));
    }

    /**
     * 修改
     * @param advpos
     * @return
     */
    @PostMapping("/update")
    public ResponseEntity<Result> update(@RequestBody Advpos advpos ){
       service.updateById(advpos);
        return  ResponseEntity.ok(new Result(0,"成功"));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    public ResponseEntity<Result> update(@RequestParam String id ){
        service.remove(id);
        return  ResponseEntity.ok(new Result(0,"成功"));
    }

    @GetMapping("/all")
    public ResponseEntity<Result> getAll(){
        List<Advpos> list = service.list();
        return  ResponseEntity.ok(new Result(0,"成功",list));
    }

    @GetMapping("/rowInfo")
    public ResponseEntity<Result> getRowInfo(@RequestParam String id){
        Advpos advpos = service.getById(id);
        return  ResponseEntity.ok(new Result(0,"成功",advpos));
    }

    @PostMapping("/add")
    public ResponseEntity<Result> save(@RequestBody Advpos advpos){
        service.save(advpos);
        return  ResponseEntity.ok(new Result(0,"成功"));
    }



}
